import React, { useEffect, useRef, useState } from "react";
import logo from "./logo.svg";
import "./App.css";

function App() {
  const [count, setCount] = useState(1);
  const ref = useRef<number>();

  useEffect(() => {
    ref.current = count
  })
  return (
    <div>
      <h2>当前值： {count}</h2>
      <h2>前值： {ref.current}</h2>   
      <button onClick={() => setCount(count + 1)}>+1</button>
    </div>
  );
}

export default App;
